package io.renren.modules.generator.controller;

import java.util.Arrays;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.renren.modules.generator.entity.DeviceDayEntity;
import io.renren.modules.generator.service.DeviceDayService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-09-08 14:27:29
 */
@RestController
@RequestMapping("generator/deviceday")
@Api("接口")
public class DeviceDayController {
    @Autowired
    private DeviceDayService deviceDayService;

    /**
     * 按24小时查询各个设备的指标
     * @param deviceCodes 设备编码组
     * @param time 需要查询的时间
     * @return
     */
    @RequestMapping("/quota")
    @ApiOperation("分页列表")
    public R quota(
            @RequestParam("deviceCodes") String[] deviceCodes,
            @RequestParam("time") String time
    ){
        return R.ok().put("data", deviceDayService.quota(deviceCodes,time));
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    @ApiOperation("分页列表")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = deviceDayService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{deviceCodeTime}")
    @ApiOperation("根据id获取实体")
    public R info(@PathVariable("deviceCodeTime") String deviceCodeTime){
		DeviceDayEntity deviceDay = deviceDayService.getById(deviceCodeTime);

        return R.ok().put("deviceDay", deviceDay);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @ApiOperation("保存")
    public R save(@RequestBody DeviceDayEntity deviceDay){
		deviceDayService.save(deviceDay);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @ApiOperation("更新")
    public R update(@RequestBody DeviceDayEntity deviceDay){
		deviceDayService.updateById(deviceDay);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @ApiOperation("删除")
    public R delete(@RequestBody String[] deviceCodeTimes){
		deviceDayService.removeByIds(Arrays.asList(deviceCodeTimes));

        return R.ok();
    }

}
